define [
  'lib/backbone_setup'
  'chaplin'
  'layout'
  'dispatcher'
  'router'
  'lib/feedback'
  'lib/underscore_mixins'
  'lib/validate_setup'
  'lib/mask_setup'
], () ->

  'use strict'

  Chaplin    = require 'chaplin'
  Layout     = require 'layout'
  Dispatcher = require 'dispatcher'
  Router     = require 'router'
  ajaxSetup  = require 'lib/ajax_setup'

  class Application extends Chaplin.Application

    # Override Attributtes
    # =============================================================
    title: 'Banklion'

    # Override Methods
    # =============================================================

    initialize: ->
      super
      @subscribeEvent 'router:match', -> @publishEvent 'menu:updateActive'

    initLayout: (options = {}) ->
      options.title ?= @title
      @layout = new Layout options

    initDispatcher: (options) ->
      @dispatcher = new Dispatcher options

    initRouter: (routes, options) ->
      # Save the reference for testing introspection only.
      # Modules should communicate with each other via **publish/subscribe**.
      @router = new Router options

      # Register any provided routes.
      routes? @router.match
